//
//  AddUserFullNameCell.swift
//  koolcar
//
//  Created by xiantian on 2023/9/20.
//

import UIKit
class AddUserFullNameCell: UITableViewCell {
   ///*名字
    var firstNameTopLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 1
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        return tempLab
    }()
    
    ///*姓氏
    var lastNameTopLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 1
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        return tempLab
    }()
    
    //名输入框
    var firstNameTF: UITextField = {
        let textField = UITextField(frame: CGRect.zero)
        textField.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        textField.textColor = Theme.titleLabColor
        textField.layer.cornerRadius = 8
        textField.layer.borderWidth = 1
        textField.layer.borderColor = Theme.tfBorderColor.cgColor
        textField.layer.masksToBounds = true
        textField.clearButtonMode = .whileEditing
        textField.returnKeyType = .next
        textField.keyboardType = .default
        let leftView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 10, height: 10))
        textField.leftView = leftView
        textField.leftViewMode = .always
        textField.tag = 2
        return textField
        
    }()
    
    //姓输入框
    var lastNameTF: UITextField = {
        let textField = UITextField(frame: CGRect.zero)
        textField.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        textField.textColor = Theme.titleLabColor
        textField.layer.cornerRadius = 8
        textField.layer.borderWidth = 1
        textField.layer.borderColor = Theme.tfBorderColor.cgColor
        textField.layer.masksToBounds = true
        textField.clearButtonMode = .whileEditing
        textField.returnKeyType = .done
        textField.keyboardType = .default
        let leftView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 10, height: 10))
        textField.leftView = leftView
        textField.leftViewMode = .always
        textField.tag = 1
        return textField
    }()
    
    
    var firstMsgLab: UILabel = {
        let msgLab = UILabel()
        msgLab.textColor = Theme.redColor
        msgLab.backgroundColor = UIColor.clear
        msgLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 11)
        msgLab.numberOfLines = 0
        msgLab.lineBreakMode = .byTruncatingTail
        msgLab.textAlignment = .left
        return msgLab
        
    }()
    
    var lastMsgLab: UILabel = {
        let msgLab = UILabel()
        msgLab.textColor = Theme.redColor
        msgLab.backgroundColor = UIColor.clear
        msgLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 11)
        msgLab.numberOfLines = 0
        msgLab.lineBreakMode = .byTruncatingTail
        msgLab.textAlignment = .left
        return msgLab
        
    }()
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(lastNameTopLab)
        contentView.addSubview(firstNameTopLab)
        self.contentView.addSubview(lastNameTF)
        self.contentView.addSubview(lastMsgLab)
        self.contentView.addSubview(firstNameTF)
        self.contentView.addSubview(firstMsgLab)
        
        self.addSnpLayout()
    }
    
    func addSnpLayout(){
        let maxWidth: CGFloat = (kScreenWidth - 42)/2
        
        firstNameTopLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.top.equalTo(0)
            make.height.greaterThanOrEqualTo(0)
            make.width.equalTo(maxWidth)
        }
        
        lastNameTopLab.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.right.equalTo(-14)
            make.width.equalTo(maxWidth)
            make.height.greaterThanOrEqualTo(0)
        }
        
        firstNameTF.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.top.equalTo(firstNameTopLab.snp.bottom).offset(6)
            make.height.equalTo(44)
            make.width.equalTo(maxWidth)
            
        }
        
        firstMsgLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.top.equalTo(firstNameTF.snp.bottom).offset(4)
            make.width.equalTo(maxWidth)
            make.bottom.lessThanOrEqualTo(-12)
        }
        
        lastNameTF.snp.makeConstraints { make in
            make.top.equalTo(firstNameTF.snp.top)
            make.height.equalTo(44)
            make.right.equalTo(-14)
            make.width.equalTo(maxWidth)
        }
        
        lastMsgLab.snp.makeConstraints { make in
            make.top.equalTo(lastNameTF.snp.bottom).offset(4)
            make.right.equalTo(-14)
            make.width.equalTo(maxWidth)
            make.bottom.lessThanOrEqualTo(-12)
        }
    }
    
    func showTopTitleLab() {
        //名
        let tempStr1 = String(format: "*%@", MMLocalizedString("profile_name", comment: "名字"))
        let attr1 = NSMutableAttributedString.init(string: tempStr1)
        attr1.addAttributes([NSAttributedStringKey.foregroundColor: Theme.redColor], range: NSRange.init(location: 0, length: 1))
        self.firstNameTopLab.attributedText = attr1
       
        //姓
        let tempStr2 = String(format: "*%@", MMLocalizedString("profile_family", comment: "姓氏"))
        let attr2 = NSMutableAttributedString.init(string: tempStr2)
        attr2.addAttributes([NSAttributedStringKey.foregroundColor: Theme.redColor], range: NSRange.init(location: 0, length: 1))
        self.lastNameTopLab.attributedText = attr2
        
        self.lastNameTopLab.snp.updateConstraints { make in
            make.height.greaterThanOrEqualTo(22)
        }
        self.firstNameTopLab.snp.updateConstraints { make in
            make.height.greaterThanOrEqualTo(22)
        }
        self.updateConstraints()
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
